package com.speechb.bean;

import com.speechb.common.text.TextUtil;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.io.Serializable;

public class ComParaBean implements Serializable {
    private String userAgent="";
    private  boolean isCompress=true;
    /*  HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();*/
    public static ComParaBean getComParaBean(){
       ComParaBean comParaBean= (ComParaBean) ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession().getAttribute("com_para_bean");
       if(comParaBean==null){
           comParaBean=new ComParaBean();
           setComParaBean(comParaBean);
       }
       return comParaBean;
    }
    public static void setComParaBean(ComParaBean bean){
         ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession().setAttribute("com_para_bean",bean);
    }
    public static void setIsCompress(boolean isCompress){
        getComParaBean().isCompress=isCompress;
    }
    public static String getUserAgent(){
        ComParaBean bean=getComParaBean();
        if(bean==null){
            return null;
        }
        return bean.userAgent;
    }
    public static boolean getIsCompress(){
        ComParaBean bean=getComParaBean();
        if(bean==null){
            return true;
        }
        return bean.isCompress;
    }
    public static boolean isMobilePhone(){
        String userAgent=getUserAgent();
        if(!TextUtil.isEmpty(userAgent)||userAgent.contains("mobile_phone")){
          return true;
        }
        return false;
    }

}
